package mid

func SumDigitDifferences(nums []int) int64 {
	res := int64(0)
	for nums[0] > 0 {
		cnt := make([]int, 10)
		for i := 0; i < len(nums); i++ {
			cnt[nums[i]%10]++
			nums[i] /= 10
		}
		for i := 0; i < 10; i++ {
			res += int64(len(nums)-cnt[i]) * int64(cnt[i])
		}
	}
	return res / 2
}
